
// const BASE_URL = "https://tea.qingnian8.com/api/bizhi"
import {packApiUrl} from "./common.js"
export const request = (config={}) => {
	let {
		url,
		method="get",
		data={},
		header={}
	}=config
	// url = BASE_URL+url
	url = packApiUrl(url) 
	header['access-key'] = 'liuguodong'
	return new Promise((resolve,rejects) => {
		uni.request({
			url,
			method,
			data,
			header,
			success: res => {
				if(res.data.errCode===0){
					resolve(res.data.data)
				}else if(res.data.errCode===400){
					uni.showModal({
						title:"请求错误",
						content:res.data.errMsg,
					})
					rejects(res.data)
				}
			},
			fail: res => {
				uni.showToast({
					title:"错误",
					icon:"none"
				})
				rejects(res)
			}
		})
	})
}